from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep
# 1.导入等待类
from selenium.webdriver.support.wait import WebDriverWait

driver = webdriver.Firefox()
driver.maximize_window()
# 设置隐式等待，针对于所有的元素
# driver.implicitly_wait(20)
url = 'file:///C:/Users/TEACHER/Desktop/NSD2405/html/registerA.html'
driver.get(url)
# 2.实例化一个等待对象
# timeout 等待的时间
# poll_frequency 轮询的频率
wait = WebDriverWait(driver, timeout=20, poll_frequency=0.5)
# username = driver.find_element(By.CSS_SELECTOR, '#user')
# username.send_keys('admin')
# 3.显示等待，针对于特定的某个元素设置的等待策略
username = wait.until(lambda x: x.find_element(By.CSS_SELECTOR, '#user'))
username.send_keys('admin')
sleep(3)
driver.quit()